package com.uchedao.vehicledetection.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Alex on 2015/6/16.
 */
public class JudgeUtil {

    /**
     * //@Title: isPhoneNumberValid
     * //@Description: 验证号码 手机号 固话均可
     * //@author qinyl
     * //@date 2014年6月20日 下午3:16:03
     * //@param @param phoneNumber
     * //@param @return 设定文件
     * //@return boolean 返回类型
     * //@throws
     */
    public static boolean isPhoneNumberValid(String phoneNumber) {
        boolean isValid = false;
        String expression = "^(010|02\\d|0[3-9]\\d{2})?\\d{6,8}$";
        Pattern pattern = Pattern.compile(expression);
        Matcher matcher = pattern.matcher(phoneNumber);
        return matcher.matches();
    }

    /**
     * 判断手机号码
     *
     * @param mobiles 手机号码
     * @return
     */
    public static boolean isMobileNO(String mobiles) {
        Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
        Matcher m = p.matcher(mobiles);
        return m.matches();
    }

    /**
     * 判断邮编
     *
     * @param post 邮编
     * @return
     */
    public static boolean isZipNO(String post) {
        String str = "^[1-9][0-9]{5}$";
        return Pattern.compile(str).matcher(post).matches();
    }

    /**
     * 判断邮箱是否合法
     *
     * @param email 邮箱地址
     * @return
     */
    public static boolean isEmail(String email) {
        if (null == email || "".equals(email)) return false;
//        Pattern p = Pattern.compile("\\w+@(\\w+.)+[a-z]{2,3}"); //简单匹配
        Pattern p = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");//复杂匹配
        Matcher m = p.matcher(email);
        return m.matches();
    }
}
